'use strict';

const conn = require('../../libs/DB/Conn');
module.exports = async function (params) {
    let searchTest = params.searchText;
    let pAgentId = params.pAgentId;
    let searchStr = '';
    if (searchTest) searchStr += ` AND agent_name LIKE "%${searchTest}%"`;

    let querySql = `SELECT
                  agent_id AS agentId,
                  agent_name AS agentName,
                  agent_principal AS agentPrincipal,
                  phone_number AS phoneNumber ,
                  company_addr AS companyAddr,
                  DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') AS createTime
                FROM
                    agent_file
                WHERE
                    delete_sign = 1 AND p_id = ? 
                    ${searchStr} 
                ORDER BY
                    create_time DESC`;
    let result = await conn(querySql, [pAgentId]);

    return {success: true, data: result}
};